package com.sakura.oj.judge.codesandbox.impl;


import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.sakura.oj.judge.codesandbox.CodeSandbox;
import com.sakura.oj.judge.codesandbox.model.ExecuteCodeRequest;
import com.sakura.oj.judge.codesandbox.model.ExecuteCodeResponse;
import lombok.extern.slf4j.Slf4j;

/**
 * 远程代码沙箱（仅为了跑通业务流程）
 */
@Slf4j
public class RemoteCodeSandbox implements CodeSandbox {
    @Override
    public ExecuteCodeResponse executeCode(ExecuteCodeRequest executeCodeRequest) {
        log.info("-------------代码沙箱请求开始-------------");
        log.info("代码沙箱请求参数：{}", executeCodeRequest);

        String responseStr = HttpUtil.post(executeCodeRequest.getUrl(), JSONUtil.toJsonStr(executeCodeRequest));
        // 转换
        ExecuteCodeResponse executeCodeResponse = JSONUtil.toBean(responseStr, ExecuteCodeResponse.class);

        log.info("-------------代码沙箱请求结束-------------");

        return executeCodeResponse;
    }
}
